package org.mock.common;

import lombok.Data;

@Data
public class ResultBaiFenHui<T> {

    private Boolean result;

    private String errCode;

    private String desc;

    /**
     * 泛型，方便携带不同类型的数据
     */
    private T data;

    /**
     * 静态的构造方法？
     *
     * @param <T>
     * @return
     */
    public static <T> ResultBaiFenHui<T> success() {
        ResultBaiFenHui<T> result = new ResultBaiFenHui<>();
        result.setResult(true);
        result.setErrCode("000");
        result.setDesc("成功");
        return result;
    }

    public static <T> ResultBaiFenHui<T> success(T data) {
        ResultBaiFenHui<T> result = new ResultBaiFenHui<>();
        result.setResult(true);
        result.setErrCode("000");
        result.setDesc("成功");
        result.setData(data);
        return result;
    }

    public static <T> ResultBaiFenHui<T> error(String errCode, String desc) {
        ResultBaiFenHui<T> result = new ResultBaiFenHui<>();
        result.setResult(false);
        result.setErrCode(errCode);
        result.setDesc(desc);
        return result;
    }
}
